//
//  TabBarController.m
//  17DianYing
//
//  Created by apple on 15/9/9.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "TabBarController.h"
#import "ParticipateViewController.h"

@interface TabBarController ()<UITabBarControllerDelegate>

@end

@implementation TabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate=self;
    
    UIStoryboard * story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    UIImage * participate = [[UIImage imageNamed:@"canyu"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage * participateHL = [[UIImage imageNamed:@"canyu"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal
                          ];
    UITabBarItem * participateItem = [[UITabBarItem alloc]initWithTitle:@"参与" image:participate selectedImage:participateHL];
    UIViewController * participateVC = [story instantiateViewControllerWithIdentifier:@"nav1"];
//    [self.tabBarController addChildViewController:participateVC];
  participateVC.tabBarItem = participateItem;
    
    
    UIImage * cover = [[UIImage imageNamed:@"xiaoxi"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage * coverHL = [[UIImage imageNamed:@"xiaoxi"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal
                               ];
    UITabBarItem * coverItem = [[UITabBarItem alloc]initWithTitle:@"消息" image:cover selectedImage:coverHL];
    UIViewController * coverVC = [story instantiateViewControllerWithIdentifier:@"nav2"];
    coverVC.tabBarItem = coverItem;
    
    
    
    UIImage * allraise = [[UIImage imageNamed:@"zhongchou"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage * allraiseHL = [[UIImage imageNamed:@"zhongchou"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal
                               ];
    UITabBarItem * allraiseItem = [[UITabBarItem alloc]initWithTitle:@"众筹" image:allraise selectedImage:allraiseHL];
    UIViewController * allraiseVC = [story instantiateViewControllerWithIdentifier:@"nav3"];
    allraiseVC.tabBarItem = allraiseItem;
    
    
    UIImage * found = [[UIImage imageNamed:@"faxian"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage * foundHL = [[UIImage imageNamed:@"faxian"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal
                               ];
    UITabBarItem * foundItem = [[UITabBarItem alloc]initWithTitle:@"发现" image:found selectedImage:foundHL];
    UIViewController * foundVC = [story instantiateViewControllerWithIdentifier:@"nav4"];
    foundVC.tabBarItem = foundItem;
    
    
    UIImage * self1 = [[UIImage imageNamed:@"wode"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage * selfHL = [[UIImage imageNamed:@"wode"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal
                               ];
    UITabBarItem * selfItem = [[UITabBarItem alloc]initWithTitle:@"个人中心" image:self1 selectedImage:selfHL];
    UIViewController * selfVC = [story instantiateViewControllerWithIdentifier:@"nav5"];
    selfVC.tabBarItem = selfItem;
    
    
    
    
    self.viewControllers = @[participateVC,coverVC,allraiseVC,foundVC,selfVC];
    // Do any additional setup after loading the view.
}

// 控制器即将显示的时候调用
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
//    NSLog(@"%@ -  控制器即将显示", [self class]);
    ParticipateViewController *p = [[ParticipateViewController alloc]init];

    NSURL *url = [NSURL URLWithString:@"http://www.17dianying.cn/v3/canyu/index.html"];
    
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    [p.Webview loadRequest:req];

}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    ParticipateViewController *p = [[ParticipateViewController alloc]init];
    
    NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
    
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    [p.Webview loadRequest:req];
}
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{

    if (tabBarController.selectedIndex == 1) {
        NSLog(@"111111111111");
    }
    return YES;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{

    ParticipateViewController *p = [[ParticipateViewController alloc]init];
    
    UIViewController *vc=tabBarController.selectedViewController;
    if (self.tabBarController.selectedViewController==p) {
        NSURL *url = [NSURL URLWithString:@"http://www.17dianying.cn/v3/canyu/index.html"];
        
        NSURLRequest *req = [NSURLRequest requestWithURL:url];
        [p.Webview loadRequest:req];
    }
 
    [p.Webview reload];
    NSLog(@"=======");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
